#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <gtest/gtest.h>
#include "buffer.h"


TEST(BufferTest, Init)
{
	int size = 1000;
	{
		WriteReadBuffer buffer(size);
		printf("buffer free size : %d and buffer data size : %d.\n", buffer.BufferFreeSize(), buffer.BufferDataSize());
	}
	{
		WriteReadBuffer buffer;
		printf("buffer free size : %d and buffer data size : %d.\n", buffer.BufferFreeSize(), buffer.BufferDataSize());
	}
	{

	}
}

TEST(BufferTest, PushData)
{
	int size = 1000;
	WriteReadBuffer buffer;
	for (int index = 0; index < size; index++)
	{
		uint8_t ch = rand() % 10 + '0';
		buffer.PushDataToBuffer(&ch, 1);
	}
	printf("buffer free size : %d and buffer data size : %d.\n", buffer.BufferFreeSize(), buffer.BufferDataSize());
	for (int index = 0; index < size; index++)
	{
		uint8_t ch = rand() % 10 + '0';
		buffer.PushDataToBuffer(&ch, 1);
		EXPECT_EQ(*(buffer.BufferData() + buffer.BufferDataSize() - 1), ch);
	}
	printf("buffer free size : %d and buffer data size : %d.\n", buffer.BufferFreeSize(), buffer.BufferDataSize());
	for (int index = 0; index < size - rand() % 200; index++)
	{
		uint8_t ch = rand() % 10 + '0';
		buffer.PushDataToBuffer(&ch, 1);
	}
	printf("buffer free size : %d and buffer data size : %d.\n", buffer.BufferFreeSize(), buffer.BufferDataSize());
	buffer.RemoveSize(size % buffer.BufferDataSize());
	printf("buffer free size : %d and buffer data size : %d.\n", buffer.BufferFreeSize(), buffer.BufferDataSize());
	buffer.RemoveSize(buffer.BufferDataSize());
	printf("buffer free size : %d and buffer data size : %d.\n", buffer.BufferFreeSize(), buffer.BufferDataSize());
}

